package com.chuanyang.driverh.mainhome.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseListAdapter;
import com.chuanyang.driverh.response2.join.ResultFleetJoinList;
import com.chuanyang.driverh.utils.BitmapUtil;
import com.chuanyang.driverh.utils.StringUtil;
import com.chuanyang.driverh.utils.widget.GlideCircleTransform;


public class FleetJoinAdapter extends BaseListAdapter<ResultFleetJoinList.DataBeanX.DataBean> {
    private Activity activity;

    public FleetJoinAdapter(Activity activity) {
        super(activity);//此处不传入集合，则默认集合长度为0，在setdataresult（）方法中，添加数据并刷新
        this.activity=activity;
    }

    @Override
    public View getZkView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView == null) {
            convertView = getInflater().inflate(R.layout.item_fleet_list, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.iv_photo = (ImageView)convertView.findViewById(R.id.iv_photo);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_car_num = (TextView) convertView.findViewById(R.id.tv_car_num);
            viewHolder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);
            viewHolder.tv_all_dan = (TextView) convertView.findViewById(R.id.tv_all_dan);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
      final   ResultFleetJoinList.DataBeanX.DataBean  data= getItem(position);
        Glide.with(activity).load(data.getImage()).crossFade().placeholder(R.mipmap.group_chat).
                error(R.mipmap.group_chat).transform(new GlideCircleTransform(activity)).into(viewHolder.iv_photo);
        //BitmapUtil.showImgForNetPath(data.getImage(),viewHolder.iv_photo);
        viewHolder.tv_name.setText(data.getUsername());
        viewHolder.tv_car_num.setText(data.getPlateNumber());
        viewHolder.tv_phone.setText(StringUtil.handlePhoneNumShow(data.getPhoneCall()));
        viewHolder.tv_all_dan.setText("共计"+data.getWaybillNum()+"单");

        return convertView;
    }

    class ViewHolder {
        ImageView iv_photo;
        TextView tv_name;
        TextView tv_car_num;
        TextView tv_phone;
        TextView tv_all_dan;
    }
}
